package training.list;


public class ListNodeTestHelper {

    public static void print(ListNode listNode) {
        System.out.println(toString(listNode));
    }

    public static String toString(ListNode listNode) {
        String str = "{" + listNode.val;
        while (listNode.next != null) {
            str += "," + listNode.next.val;
            listNode = listNode.next;
        }
        str += "}";
        return str;
    }

    public static ListNode newListNode(int headVal, int... vals) {
        ListNode pHead = new ListNode(headVal);
        appendListNode(pHead, vals);
        return pHead;
    }

    public static int appendListNode(ListNode node, int... vals) {
        int i =0;
        for(; i < vals.length; i++) {
            node.next = new ListNode(vals[i]);
            node = node.next;
        }
        return i + 1;
    }

}
